import java.text.SimpleDateFormat;
import java.util.Date;
import java.text.DateFormat;
import java.text.ParseException;

class Date_01{
  public static void main(String args[]) throws ParseException {
    Date date = new Date();

    SimpleDateFormat date_1 = new SimpleDateFormat("YYYY");
    SimpleDateFormat date_2 = new SimpleDateFormat("YYYY-MM-dd");
    SimpleDateFormat date_3 = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
    SimpleDateFormat date_4 = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
    /*
    1. 年月日
    */
    System.out.println("date:"+date); //Mon Aug 19 22:35:58 CST 2019
    System.out.println("date:"+date_1.format(date)); //date:2019
    System.out.println("date:"+date_2.format(date)); //date:2019-08-19
    System.out.println("date:"+date_3.format(date)); //date:2019-08-19 22:49:47
    
    /*
    2. 时间戳
    */
    System.out.println("time:"+date.getTime()/1000); //time:1566226349

    /*
    3. 时间转换
    */
    int times = 1566226349;
    Date tDate = new Date(times);
    String dateStr = "2015-09-09 23:0:0";
    //date4.format(tDate);
    
    System.out.println("date:"+date_3.format(tDate)); //时间戳转 年月日
    Date dtf = (Date) date_4.parse(dateStr);
    System.out.println("date:"+ dtf); //时间戳转 年月日
    


  }
}